﻿Imports System.Data.SqlClient

Public Class clsConceptos
    Private mintIdConcepto As Integer
    Private mstrCodigoConcepto As String
    Private mstrNombreConcepto As String
    Private mstrCodigoRuta As String
    Private mstrNombreRuta As String
    Private mstrTipo As String
    Public Property IdConcepto() As Integer
        Get
            Return mintIdConcepto
        End Get
        Set(ByVal value As Integer)
            mintIdConcepto = value
        End Set
    End Property
    Public Property CodigoConcepto() As String
        Get
            Return mstrCodigoConcepto
        End Get
        Set(ByVal value As String)
            mstrCodigoConcepto = value
        End Set
    End Property
    Public Property NombreConcepto() As String
        Get
            Return mstrNombreConcepto
        End Get
        Set(ByVal value As String)
            mstrNombreConcepto = value
        End Set
    End Property
    Public Property CodigoRuta() As String
        Get
            Return mstrCodigoRuta
        End Get
        Set(ByVal value As String)
            mstrCodigoRuta = value
        End Set
    End Property
    Public Property NombreRuta() As String
        Get
            Return mstrNombreRuta
        End Get
        Set(ByVal value As String)
            mstrNombreRuta = value
        End Set
    End Property
    Public Property Tipo As String
        Get
            Return mstrTipo
        End Get
        Set(value As String)
            mstrTipo = value
        End Set
    End Property

    Public Sub New()
        mintIdConcepto = 0
        mstrCodigoConcepto = ""
        mstrNombreConcepto = ""
        mstrCodigoRuta = ""
        mstrNombreRuta = ""
        mstrTipo = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Conceptos (" & _
                            "IdConcepto," & _
                            "CodigoConcepto," & _
                            "NombreConcepto," & _
                            "CodigoRuta," & _
                            "NombreRuta," & _
                            "Tipo)" & _
                            "VALUES (" & _
                            "@IdConcepto," & _
                            "@CodigoConcepto," & _
                            "@NombreConcepto," & _
                            "@CodigoRuta," & _
                            "@NombreRuta," & _
                            "@Tipo)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdConcepto", mintIdConcepto)
        Command.Parameters.AddWithValue("CodigoConcepto", mstrCodigoConcepto)
        Command.Parameters.AddWithValue("NombreConcepto", mstrNombreConcepto)
        Command.Parameters.AddWithValue("CodigoRuta", mstrCodigoRuta)
        Command.Parameters.AddWithValue("NombreRuta", mstrNombreRuta)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
       
        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update Conceptos Set " & _
                    "IdConcepto=@IdConcepto," & _
                    "CodigoConcepto=@CodigoConcepto," & _
                    "NombreConcepto=@NombreConcepto," & _
                    "CodigoRuta=@CodigoRuta," & _
                    "NombreRuta=@NombreRuta," & _
                    "Tipo=@Tipo " & _
                    "Where IdConcepto=@IdConcepto"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
         Command.Parameters.AddWithValue("IdConcepto", mintIdConcepto)
        Command.Parameters.AddWithValue("CodigoConcepto", mstrCodigoConcepto)
        Command.Parameters.AddWithValue("NombreConcepto", mstrNombreConcepto)
        Command.Parameters.AddWithValue("CodigoRuta", mstrCodigoRuta)
        Command.Parameters.AddWithValue("NombreRuta", mstrNombreRuta)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
